#include <stdio.h>
#include <stdlib.h>
#define SIZE 10

int main()
{
    int mNew[SIZE][SIZE], i, j, t = 0, count = 0, x, y, k;

    int m[SIZE][SIZE] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                                  {0, 1, 1, 0, 0, 1, 0, 0, 0, 0},
                                  {0, 0, 1, 0, 0, 0, 1, 1, 1, 0},
                                  {0, 1, 0, 0, 0, 1, 0, 1, 0, 0},
                                  {0, 0, 1, 1, 1, 0, 1, 1, 0, 0},
                                  {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                                  {0, 1, 0, 0, 1, 0, 1, 0, 0, 0},
                                  {0, 0, 0, 0, 1, 0, 0, 0, 1, 0},
                                  {0, 1, 0, 1, 0, 0, 0, 1, 0, 0},
                                  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

    while (1)
    {
        for (x = 0; x < 5000; ++x)
            for(y = 0; y < 5000; ++y)
                ++k;
        system("cls");
        for (i = 1; i < SIZE; ++i)
            for (j = 1; j < SIZE; ++j)
            {
                count = 0;

                if (m[i - 1][j] == 1)
                    ++count;
                if (m[i][j + 1] == 1)
                    ++count;
                if (m[i + 1][j] == 1)
                    ++count;
                if (m[i][j - 1] == 1)
                    ++count;
                if (m[i - 1][j - 1] == 1)
                    ++count;
                if (m[i - 1][j + 1] == 1)
                    ++count;
                if (m[i + 1][j + 1] == 1)
                    ++count;
                if (m[i + 1][j - 1] == 1)
                    ++count;


                if(m[i][j] == 1)
                {
                    if (count < 2)
                        mNew[i][j] = 0;
                    if (count == 2 || count == 3)
                        mNew[i][j] = 1;
                    if (count > 3)
                        mNew[i][j] = 0;
                }

                if(m[i][j] == 0 && (count == 2 || count == 3))
                    mNew[i][j] = 1;
            }

        for (i = 1; i < SIZE; ++i)
        {
            for (j = 1; j < SIZE; ++j)
            {
                m[i][j] = mNew[i][j];

                if (mNew[i][j] == 1)
                    printf("%c", 219);
                else
                    printf("%c", 176);
            }
            printf("\n");
        }
        ++t;
    }
    return 0;
}

